/**
 * @Author：ming
 * @Date：2023/10/6 9:44 PM
 * @Filename：Lc215
 */

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author ming
 */
public class Lc215 {
    public int findKthLargest(int[] nums, int k) {
        int len = nums.length;
        PriorityQueue<Integer> dui = new PriorityQueue<>(k, Comparator.comparingInt(a->a));

        for (int i = 0; i < k; i++) {
            dui.add(nums[i]);
        }

        for (int i = k; i < len; i++) {
            int temp = dui.peek();
            if(nums[i]>temp){
                dui.poll();
                dui.add(nums[i]);
            }
        }
        return dui.peek();
    }
}
